package cs275.ants.agent;

import static org.easymock.EasyMock.expect;

import java.util.List;

import junit.framework.TestCase;

import org.easymock.EasyMock;
import org.easymock.IMocksControl;

import com.google.common.collect.Lists;

import cs275.ants.graph.base.Graph;
import cs275.ants.graph.base.GraphVertex;

public class AntManagerTest extends TestCase {

	private IMocksControl control;

	@Override
	protected void setUp() throws Exception {
		control = EasyMock.createControl();
	}

	public void testMoveAllAnts() {
		Ant ant1 = control.createMock(Ant.class);
		Ant ant2 = control.createMock(Ant.class);
		Ant ant3 = control.createMock(Ant.class);
		Ant ant4 = control.createMock(Ant.class);
		Ant ant5 = control.createMock(Ant.class);
		List<Ant> ants = Lists.newArrayList(ant1, ant2, ant3, ant4, ant5);
		AntManager manager = new AntManager(ants);

		GraphVertex someSpot = new GraphVertex(0,0);
		expect(ant1.chooseNextMove()).andReturn(someSpot);
		expect(ant1.move(someSpot)).andReturn(true);
		expect(ant2.chooseNextMove()).andReturn(someSpot);
		expect(ant2.move(someSpot)).andReturn(true);
		expect(ant3.chooseNextMove()).andReturn(someSpot);
		expect(ant3.move(someSpot)).andReturn(true);
		expect(ant4.chooseNextMove()).andReturn(someSpot);
		expect(ant4.move(someSpot)).andReturn(true);
		expect(ant5.chooseNextMove()).andReturn(someSpot);
		expect(ant5.move(someSpot)).andReturn(true);

		control.replay();

		manager.moveAllAnts();
		control.verify();
	}
	
	public void testAddAnts() {
		Graph graph = new Graph();
		GraphVertex currentPosition = new GraphVertex(0,0);
		AntManager manager = AntManager.withAnts(5, graph, currentPosition);
		assertEquals(5, manager.getAnts().size());
		
		manager.addAnts(5, graph, currentPosition);
		assertEquals(10, manager.getAnts().size());
	}
}
